package com.taoym.voucher.xcx.controller;

import com.taoym.voucher.xcx.service.FilesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotBlank;

@RestController
@Api(tags = "文件控制器")
@Validated
public class FilesController {

    @Autowired
    private FilesService filesService;

    @PostMapping(value = "/upload")
    @ApiOperation(value = "上传文件")
    public String uploadPhoto(MultipartFile files) {
        return filesService.upload(files);
    }

    @GetMapping("/delete")
    @ApiOperation("删除文件")
    public String deletePhoto(@RequestParam @NotBlank(message = "图片地址") String url) {
        return filesService.delete(url);
    }
}
